package newfeature.jdk9;

import java.io.ByteArrayInputStream;
import java.io.ByteArrayOutputStream;
import java.io.IOException;
import java.nio.charset.StandardCharsets;

/**
 * Created by dl
 */
public class InputStreamNewMethod {
	public static void main(String[] args) throws IOException {
		ByteArrayInputStream inputStream = new ByteArrayInputStream("hello, it's me".getBytes(StandardCharsets.UTF_8));
		ByteArrayOutputStream outputStream = new ByteArrayOutputStream();
		inputStream.transferTo(outputStream);
		System.out.println("outputStream = " + outputStream.toString());

		ByteArrayInputStream inputStream2 = new ByteArrayInputStream("hello, it's me".getBytes(StandardCharsets.UTF_8));
		System.out.println("inputStream2.readNBytes(5) = " + new String(inputStream2.readNBytes(5)));
		System.out.println("inputStream2.readAllBytes() = " + new String(inputStream2.readAllBytes()));

		// it's ok not to close
	}
}
